//
//  GYCartConfirmGoodsCell.m
//  GYDemo
//
//  Created by mac on 2018/4/8.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "GYCartConfirmGoodsCell.h"
#import "Head.h"

@interface GYCartConfirmGoodsCell()
@property (nonatomic,strong) UILabel *companyNameLB;
@property (nonatomic,strong) UIButton *mobileBTN;
@property (nonatomic,strong) UIImageView *imageIV;
@property (nonatomic,strong) UILabel *nameLB;
@property (nonatomic,strong) UILabel *priceLB;
@property (nonatomic,strong) UIView *countV;
@property (nonatomic,strong) UITextField *countTF;
@property (nonatomic,strong) UILabel *countUnitLB;
@property (nonatomic,strong) UILabel *titleLB;
@property (nonatomic,strong) UILabel *signLB;
@property (nonatomic,strong) UIView *sepV;
@property (nonatomic,strong) UILabel *totalLB;
@end

@implementation GYCartConfirmGoodsCell
#pragma mark - getter and setter

-(UILabel *)companyNameLB
{
    if (!_companyNameLB) {
        _companyNameLB = [[UILabel alloc]init];
        _companyNameLB.frame = WFCGRectMake(44, 13, 200, 20);
        _companyNameLB.x = WFCGFloatX(19);
        _companyNameLB.font = SYSTEMBOLDFONT(14);
        _companyNameLB.textColor = Main_Color_Black;
    }
    return _companyNameLB;
}

-(UIButton *)mobileBTN
{
    if (!_mobileBTN) {
        _mobileBTN = [UIButton new];
        _mobileBTN.width = WFCGFloatX(100);
        _mobileBTN.height = WFCGFloatY(46);
        _mobileBTN.x = SCREEN_WIDTH - WFCGFloatX(10) - _mobileBTN.width;
        _mobileBTN.titleLabel.font = SYSTEMFONT(12);
        [_mobileBTN setTitleColor:Main_Color_Black forState:UIControlStateNormal];
        [_mobileBTN handleControlEvent:UIControlEventTouchUpInside withBlock:^{
            [[GCPresenter shareInterface]phoneCall:_model.mobile];
        }];
    }
    return _mobileBTN;
}

-(UIImageView *)imageIV
{
    if (!_imageIV) {
        _imageIV = [UIImageView new];
        _imageIV.frame = WFCGRectMake(44, 50, 90, 90);
        _imageIV.x = WFCGFloatX(19);
        _imageIV.backgroundColor = Main_Color_BG;
    }
    return _imageIV;
}
-(UILabel *)nameLB
{
    if (!_nameLB) {
        _nameLB = [[UILabel alloc]init];
        _nameLB.x = WFCGFloatX(149);
        _nameLB.y = WFCGFloatY(50);
        _nameLB.width = WFCGFloatX(212);
        _nameLB.height = WFCGFloatY(33);
        _nameLB.x = WFCGFloatX(125);
        _nameLB.font = SYSTEMBOLDFONT(13);
        _nameLB.textColor = Main_Color_Black;
    }
    return _nameLB;
}

-(UILabel *)priceLB
{
    if (!_priceLB) {
        _priceLB = [[UILabel alloc]init];
        _priceLB.x = WFCGFloatX(149);
        _priceLB.y = WFCGFloatY(115);
        _priceLB.width = WFCGFloatX(100);
        _priceLB.height = WFCGFloatY(25);
        _priceLB.x = WFCGFloatX(125);
        _priceLB.textColor = HEXCOLOR(@"#FC1B36");
        _priceLB.font = SYSTEMBOLDFONT(15);
    }
    return _priceLB;
}

-(UIView *)countV
{
    if (!_countV) {
        _countV = [UIView new];
        _countV.frame = WFCGRectMake(292, 118, 70, 25);
        _countV.x = WFCGFloatX(289);
        _countV.backgroundColor = Main_Color_BG;
        [_countV addSubview:self.countTF];
        [_countV addSubview:self.countUnitLB];
    }
    return _countV;
}

-(UITextField *)countTF
{
    if (!_countTF) {
        _countTF = [UITextField new];
        _countTF.frame = WFCGRectMake(7, 0, 70 - 7 - 5 - 17, 25);
        _countTF.enabled = NO;
        _countTF.textColor = Main_Color_Gray;
        _countTF.font = SYSTEMFONT(12);
        _countTF.keyboardType = UIKeyboardTypeNumberPad;
        _countTF.text=@"1";
    }
    return _countTF;
}

-(UILabel *)countUnitLB
{
    if (!_countUnitLB) {
        _countUnitLB = [[UILabel alloc]init];
        _countUnitLB.x = self.countTF.right;
        _countUnitLB.y = self.countTF.y;
        _countUnitLB.width = WFCGFloatX(17);
        _countUnitLB.height = WFCGFloatY(25);
        _countUnitLB.textColor = Main_Color_LightGray;
        _countUnitLB.font = SYSTEMFONT(12);
    }
    return _countUnitLB;
}
-(UILabel *)titleLB
{
    if (!_titleLB) {
        _titleLB = [UILabel new];
        _titleLB.x = WFCGFloatX(19);
        _titleLB.y = WFCGFloatY(164);
        _titleLB.width = WFCGFloatX(100);
        _titleLB.height = WFCGFloatY(45);
        _titleLB.font = SYSTEMFONT(13);
        _titleLB.textColor = Main_Color_Black;
        _titleLB.text = @"给卖家留言";
    }
    return _titleLB;
}
-(UILabel *)signLB
{
    if (!_signLB) {
        _signLB = [UILabel new];
        _signLB.x = WFCGFloatX(101);
        _signLB.y = WFCGFloatY(164);
        _signLB.width = WFCGFloatX(250);
        _signLB.height = WFCGFloatY(45);
        _signLB.font = SYSTEMFONT(13);
        _signLB.numberOfLines = 0;
        _signLB.textColor = Main_Color_Gray;
    }
    return _signLB;
}
-(UIView *)sepV
{
    if (!_sepV) {
        _sepV = [UIView new];
        _sepV.width = WF_UI_VIEW_WIDTH;
        _sepV.height = 0.7f;
        _sepV.backgroundColor = Main_Color_BG;
        _sepV.y = self.titleLB.bottom;
    }
    return _sepV;
}
-(UILabel *)totalLB
{
    if (!_totalLB) {
        _totalLB = [UILabel new];
        _totalLB.x = WF_UI_VIEW_WIDTH - WFCGFloatX(200 + 13);
        _totalLB.width = WFCGFloatX(200);
        _totalLB.y = self.signLB.bottom;
        _totalLB.height = WFCGFloatY(45);
        _totalLB.font = SYSTEMBOLDFONT(14);
        _totalLB.textColor = HEXCOLOR(@"#FC1B36");
        _totalLB.textAlignment = NSTextAlignmentRight;
    }
    return _totalLB;
}

-(UIButton *)commentBTN
{
    if (!_commentBTN) {
        _commentBTN = [UIButton new];
    }
    return _commentBTN;
}

-(void)setModel:(GYCartShopModel *)model
{
    _model = model;
    _companyNameLB.text =@"革优皮草小店";
    [_mobileBTN setTitle:_model.mobile forState:UIControlStateNormal];
    [_imageIV sd_setImageWithURL:[NSURL URLWithString:model.imgpath]];
    _nameLB.text = self.model.name;
    NSString *units = [NSString stringWithFormat:@"/%@",@"件"];
    NSString *prices = [NSString stringWithFormat:@"￥%@%@",self.model.price,units];
    NSMutableAttributedString *mastr = [[NSMutableAttributedString alloc]initWithString:prices];
    [mastr addAttribute:NSFontAttributeName value:SYSTEMFONT(12) range:NSMakeRange(0, 1)];
    [mastr addAttribute:NSFontAttributeName value:SYSTEMFONT(12) range:NSMakeRange([prices rangeOfString:units].location - 2, [prices rangeOfString:units].length + 2)];
    _priceLB.attributedText = mastr;
    _countTF.text = @"1 件";
    _countUnitLB.text = self.model.unit;
    
    NSString *str = model.comment ?: @"填写留言内容";
    _signLB.text = str;
    
    CGSize temSize = [WFFunctions WFStrGetSize:str width:_signLB.width font:_signLB.font];
    if (temSize.height > WFCGFloatY(45))
    {
        _signLB.height = temSize.height;
        _titleLB.height = temSize.height;
    }
    _commentBTN.frame = _signLB.frame;
    _sepV.y = _titleLB.bottom;
    
    NSString *finalprices = [NSString stringWithFormat:@"小计：%.2f元",_model.price.floatValue];
    NSMutableAttributedString *mastr2 = [[NSMutableAttributedString alloc]initWithString:finalprices];
    [mastr2 addAttribute:NSFontAttributeName value:SYSTEMFONT(12) range:[finalprices rangeOfString:@"小计："]];
    [mastr2 addAttribute:NSForegroundColorAttributeName value:Main_Color_Gray range:[finalprices rangeOfString:@"小计："]];
    [mastr2 addAttribute:NSFontAttributeName value:SYSTEMFONT(12) range:NSMakeRange([finalprices rangeOfString:@"."].location, finalprices.length - [finalprices rangeOfString:@"."].location)];
    _totalLB.attributedText = mastr2;
    _totalLB.y = _titleLB.bottom;
    
    self.height = _totalLB.bottom + 5;
}
#pragma mark - event
#pragma mark - method
#pragma mark - life
-(void)setFrame:(CGRect)frame
{
    frame.size.height -= 5;
    [super setFrame:frame];
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self.contentView addSubview:self.companyNameLB];
        [self.contentView addSubview:self.mobileBTN];
        [self.contentView addSubview:self.imageIV];
        [self.contentView addSubview:self.nameLB];
        [self.contentView addSubview:self.priceLB];
        [self.contentView addSubview:self.countV];
        [self.contentView addSubview:self.titleLB];
        [self.contentView addSubview:self.signLB];
        [self.contentView addSubview:self.commentBTN];
        [self.contentView addSubview:self.sepV];
        [self.contentView addSubview:self.totalLB];
    }
    return self;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}
@end
